-
Notifications
You must be signed in to change notification settings - Fork 538
fix(postgrest): cross-schema rpc setof type inference #1900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
fall back to returns type when table is in different schema fixes supabase#1845
mandarini
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @7ttp ! This is a good fix for the cross-schema type inference issue. A few things to address:
- The error message mentions wrong API. The CrossSchemaError type says:
Use .rpc<YourReturnType>() to specify the return type explicitly.
But rpc doesn't accept a return type parameter. The JSDoc example correctly shows .overrideTypes<>(). Please update the error message to match:
type CrossSchemaError<TableRef extends string> = {
error: true
} & `Function returns SETOF from a different schema ('${TableRef}'). Use
.overrideTypes<YourReturnType>() to specify the return type explicitly.`
- Can you please add a type test to prevent regressions? There's an existing pattern in
packages/core/postgrest-js/test/override-types.test-d.ts. Something like:
// Test cross-schema rpc falls back to Returns type
{
const result = await postgrest
.schema('other_schema')
.rpc('cross_schema_fn', {})
expectType<{ id: string; user_id: string }[]>(result.data)
}
Otherwise the approach looks good. Falling back to Returns type when the table isn't in the current schema is the right solution, and fixing the Relationships lookup to handle missing views is a nice catch.
Updated everything as requested, |
mandarini
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Approving!
summary
Fixes a type inference failure when calling
schema().rpc().select()on functions that returnSETOFfrom a different schema.changes
Returnstype whenSetofOptions.toreferences a table outside the current schemaCrossSchemaErrorwith a clear message when the return type cannot be inferredRelationshipslookup to returnnullinstead of throwing when a view is missingoverrideTypesworkaround for cross-schema functionsfixes
Closes #1845